package com.feonix.common.view.head;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.feonix.common.BaseInfo;
import com.feonix.common.util.StringUtil;

public class ImportResourceTag extends RequestContextAwareTag {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String path = "";

	private String type = "";

	@Override
	protected int doStartTagInternal() throws Exception {
		String str = "";
		if (this.path.startsWith("/")) {
			this.path = BaseInfo.getContextPath() + this.path;
		}
		if (StringUtils.equalsIgnoreCase(this.type, "js")){
			str = "<script type=\"text/javascript\" src=\"" + this.path + "\"></script>\n";
		}else if (StringUtils.equalsIgnoreCase(this.type, "css"))
			str = "<link href=\"" + this.path + "\" rel=\"stylesheet\" type=\"text/css\"/>\n";
		try {
			this.pageContext.getOut().write(StringUtil.getString(str));
		} catch (Exception exception) {
			this.logger.error("模板输出失败", exception);
		}
		return 1;
	}

	public String getPath() {
		return this.path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}

}
